﻿using mediaControl.Event;
using mediaControl.Utils;
using mediaControl.Views;
using mediaControl.Vo;
using Newtonsoft.Json;
using Prism.Commands;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace mediaControl.ViewModels
{
    public class ScreenListViewModel : BindableBase
    {
        private ObservableCollection<ScreenVo> screenVos = new ObservableCollection<ScreenVo>();

        private readonly IDialogService dialogService;

        //事件聚合器
        private readonly IEventAggregator _eventAggregator;

        public DelegateCommand<Object> AddScreenCommand { get; set; }

        public DelegateCommand UpdateScreenCommand { get; set; }

        public DelegateCommand DeleteScreenCommand { get; set; }

        public DelegateCommand ClearScreenCommand { get; set; }

        public DelegateCommand CloseScreenCommand { get; set; }

        public DelegateCommand OpenScreenCommand { get; set; }

        private ScreenVo selectedItem;

        private ListBox listBox;

        private ProgramItemVo program;

        private IContainerExtension _containerExtension;

        private IRegionManager _regionManager;

        private List<string> userRegions = new List<string>();

        private List<string> screenIds = new List<string>();

        private List<string> screenViews = new List<string>() { "Screen", "Screen1", "Screen2", "Screen3", "Screen4" };

        private List<string> regions = new List<string>() { "Monitor", "Monitor1", "Monitor2", "Monitor3", "Monitor4" };

        private List<ScreenViewRegionVo> screenViewRegionVos = new List<ScreenViewRegionVo>();

        public DelegateCommand<ScreenVo> SetSelectedItemCommand { get; set; }
        public ScreenListViewModel(IDialogService dialogService, IEventAggregator eventAggregator, IContainerExtension containerExtension, IRegionManager regionManager)
        {
            _eventAggregator = eventAggregator;
            _containerExtension = containerExtension;
            _eventAggregator.GetEvent<ScreenListEvent>().Subscribe(Received);
            _eventAggregator.GetEvent<SelectedProgramItemEvent>().Subscribe(SelectedProgramItem);
            this.dialogService = dialogService;
            AddScreenCommand = new DelegateCommand<Object>(addScreen);
            UpdateScreenCommand = new DelegateCommand(updateScreen);
            SetSelectedItemCommand = new DelegateCommand<ScreenVo>(setSelectedItem);
            DeleteScreenCommand = new DelegateCommand(deleteScrren);
            ClearScreenCommand = new DelegateCommand(clearScreen);
            CloseScreenCommand = new DelegateCommand(closeScreen);
            OpenScreenCommand = new DelegateCommand(openScreen);
            _regionManager = regionManager;

            initScreenList();


        }

        private void openScreen()
        {
            if (null != selectedItem)
            {
                if (null != screenIds && screenIds.Count > 0 && screenIds.Contains(selectedItem.Id + ""))
                {
                    MessageBox.Show("屏幕已开启");
                    return;
                }
                DialogParameters parameters = new DialogParameters();
                selectedItem.IsCoincide = isCoincide(selectedItem, ScreenVos);
                parameters.Add("screen", selectedItem);
                string screenView = screenViews[0];
                
                foreach (ScreenViewRegionVo screenViewRegion in screenViewRegionVos)
                {
                    if (selectedItem.Id == screenViewRegion.ScreenId)
                    {
                        screenViewRegion.ScreenView = screenView;
                        break;
                    }
                }
                screenIds.Add(selectedItem.Id + "");


                switch (screenView)
                {
                    case "Screen":
                        Window screenWin = new Screen();
                        parameters.Add("win", screenWin);
                        screenWin.DataContext = new ScreenViewModel(_eventAggregator, parameters);
                        //sourceWindowList.Add(mp4Player);
                        //手动指定新窗口的viewModel
                        screenWin.ShowInTaskbar = false;
                        screenWin.Top = Convert.ToDouble(selectedItem.OrignY);
                        screenWin.Left = Convert.ToDouble(selectedItem.OrignX);
                        screenWin.Width = Convert.ToDouble(selectedItem.Width);
                        screenWin.Height = Convert.ToDouble(selectedItem.Height);
                        screenWin.Show();
                        screenViews.Remove(screenView);
                        selectedItem.ScreenView = "Screen";

                        break;
                    case "Screen1":
                        selectedItem.ScreenView = "Screen1";
                        Window screenWin1 = new Screen1();
                        parameters.Add("win", screenWin1);
                        screenWin1.DataContext = new ScreenViewModel1(_eventAggregator, parameters);
                        //sourceWindowList.Add(mp4Player);
                        //手动指定新窗口的viewModel
                        screenWin1.ShowInTaskbar = false;
                        screenWin1.Top = Convert.ToDouble(selectedItem.OrignY);
                        screenWin1.Left = Convert.ToDouble(selectedItem.OrignX);
                        screenWin1.Width = Convert.ToDouble(selectedItem.Width);
                        screenWin1.Height = Convert.ToDouble(selectedItem.Height);
                        screenWin1.Show();
                        screenViews.Remove(screenView);

                        break;
                    case "Screen2":
                        selectedItem.ScreenView = "Screen2";
                        Window screenWin2 = new Screen2();
                        parameters.Add("win", screenWin2);
                        screenWin2.DataContext = new ScreenViewModel2(_eventAggregator, parameters);
                        //sourceWindowList.Add(mp4Player);
                        //手动指定新窗口的viewModel
                        screenWin2.ShowInTaskbar = false;
                        screenWin2.Top = Convert.ToDouble(selectedItem.OrignY);
                        screenWin2.Left = Convert.ToDouble(selectedItem.OrignX);
                        screenWin2.Width = Convert.ToDouble(selectedItem.Width);
                        screenWin2.Height = Convert.ToDouble(selectedItem.Height);
                        screenWin2.Show();
                        screenViews.Remove(screenView);

                        break;
                    case "Screen3":
                        selectedItem.ScreenView = "Screen3";
                        Window screenWin3 = new Screen3();
                        parameters.Add("win", screenWin3);
                        screenWin3.DataContext = new ScreenViewModel3(_eventAggregator, parameters);
                        //sourceWindowList.Add(mp4Player);
                        //手动指定新窗口的viewModel
                        screenWin3.ShowInTaskbar = false;
                        screenWin3.Top = Convert.ToDouble(selectedItem.OrignY);
                        screenWin3.Left = Convert.ToDouble(selectedItem.OrignX);
                        screenWin3.Width = Convert.ToDouble(selectedItem.Width);
                        screenWin3.Height = Convert.ToDouble(selectedItem.Height);
                        screenWin3.Show();
                        screenViews.Remove(screenView);

                        break;
                    case "Screen4":
                        selectedItem.ScreenView = "Screen4";
                        Window screenWin4 = new Screen4();
                        parameters.Add("win", screenWin4);
                        screenWin4.DataContext = new ScreenViewModel4(_eventAggregator, parameters);
                        //sourceWindowList.Add(mp4Player);
                        //手动指定新窗口的viewModel
                        screenWin4.ShowInTaskbar = false;
                        screenWin4.Top = Convert.ToDouble(selectedItem.OrignY);
                        screenWin4.Left = Convert.ToDouble(selectedItem.OrignX);
                        screenWin4.Width = Convert.ToDouble(selectedItem.Width);
                        screenWin4.Height = Convert.ToDouble(selectedItem.Height);
                        screenWin4.Show();
                        screenViews.Remove(screenView);
                        break;
                    default:
                        break;
                }

                _eventAggregator.GetEvent<OpenScreenEvent>().Publish(screenIds);
            }
        }

        private void closeScreen()
        {
            if (null != selectedItem)
            {
                foreach (ScreenViewRegionVo screenViewRegion in screenViewRegionVos)
                {
                    if (selectedItem.Id == screenViewRegion.ScreenId)
                    {
                        switch (screenViewRegion.RegionName)
                        {
                            case "Monitor":
                                _eventAggregator.GetEvent<ClearMonitorEvent>().Publish();
                                break;
                            case "Monitor1":
                                _eventAggregator.GetEvent<ClearMonitor1Event>().Publish();
                                break;
                            case "Monitor2":
                                _eventAggregator.GetEvent<ClearMonitor2Event>().Publish();
                                break;
                            case "Monitor3":
                                _eventAggregator.GetEvent<ClearMonitor3Event>().Publish();
                                break;
                            case "Monitor4":
                                _eventAggregator.GetEvent<ClearMonitor4Event>().Publish();
                                break;
                        }
                        screenIds.Remove(selectedItem.Id + "");
                        screenViews.Insert(0, screenViewRegion.ScreenView);
                        break;
                    }
                }
                _eventAggregator.GetEvent<ScreenCloseEvent>().Publish(selectedItem);
                _eventAggregator.GetEvent<OpenScreenEvent>().Publish(screenIds);
            }
        }

        private void clearScreen()
        {
            if (null != selectedItem)
            {
                foreach (ScreenViewRegionVo screenViewRegion in screenViewRegionVos)
                {
                    if (selectedItem.Id == screenViewRegion.ScreenId)
                    {
                        switch (screenViewRegion.RegionName)
                        {
                            case "Monitor":
                                _eventAggregator.GetEvent<ClearMonitorEvent>().Publish();
                                break;
                            case "Monitor1":
                                _eventAggregator.GetEvent<ClearMonitor1Event>().Publish();
                                break;
                            case "Monitor2":
                                _eventAggregator.GetEvent<ClearMonitor2Event>().Publish();
                                break;
                            case "Monitor3":
                                _eventAggregator.GetEvent<ClearMonitor3Event>().Publish();
                                break;
                            case "Monitor4":
                                _eventAggregator.GetEvent<ClearMonitor4Event>().Publish();
                                break;
                        }

                        break;
                    }
                }
                _eventAggregator.GetEvent<ScreenClearEvent>().Publish(selectedItem);
            }
        }

        private void deleteScrren()
        {
            if (null == SelectedItem)
            {
                return;
            }
            IDialogParameters parameters = new DialogParameters();
            dialogService.ShowDialog("password", parameters, callback);
        }

        private void callback(IDialogResult obj)
        {
            if (obj.Result == ButtonResult.OK) {
                string filePath = AppDomain.CurrentDomain.BaseDirectory + "/Config/screenlist.info";
                try
                {

                    if (File.Exists(filePath))
                    {
                        string content = WriteFileUtil.readFile(filePath);
                        if (!String.IsNullOrEmpty(content))
                        {

                            foreach (ScreenVo screen in ScreenVos)
                            {
                                if (screen.Id == selectedItem.Id)
                                {
                                    ScreenVos.Remove(screen);
                                    break;
                                }
                            }
                            string outputJSON = JsonConvert.SerializeObject(ScreenVos);
                            WriteFileUtil.writeFile(filePath, outputJSON, "2");
                        }
                        screenIds.Remove(selectedItem.Id + "");
                        foreach (ScreenViewRegionVo screenViewRegion in screenViewRegionVos)
                        {
                            if (selectedItem.Id == screenViewRegion.ScreenId)
                            {
                                screenViewRegionVos.Remove(screenViewRegion);
                                screenViews.Insert(0, screenViewRegion.ScreenView);
                                regions.Insert(0, screenViewRegion.RegionName);
                                break;
                            }
                        }
                        _eventAggregator.GetEvent<ScreenCloseEvent>().Publish(selectedItem);
                        _eventAggregator.GetEvent<OpenScreenEvent>().Publish(screenIds);
                        _eventAggregator.GetEvent<RefreshSorceListEvent>().Publish(program);
                        foreach (ScreenVo vo in ScreenVos)
                        {
                            vo.IsCoincide = isCoincide(vo, ScreenVos);
                        }
                        _eventAggregator.GetEvent<UpdateCoincideEvent>().Publish(ScreenVos);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"无法创建文件：{ex.Message}");
                    MessageBox.Show($"无法创建文件：{ex.Message}");
                    return;
                }
            }
        }

        private void SelectedProgramItem(ProgramItemVo obj)
        {
            program = obj;
        }

        private void updateScreen()
        {
            IDialogParameters parameters = new DialogParameters();
            dialogService.ShowDialog("password", parameters, updateCallback);
            
        }
        private void updateCallback(IDialogResult obj) {
            if (obj.Result == ButtonResult.OK)
            {
                IDialogParameters parameters = new DialogParameters();
                parameters.Add("flag", "1");
                parameters.Add("screen", SelectedItem);
                dialogService.ShowDialog("screenSetting", parameters, addCallback);
            }
        }
        private void setSelectedItem(ScreenVo obj)
        {
            SelectedItem = obj;
        }
       
        private void addScreen(Object obj)
        {
            //listBox = obj as ListBox;
            IDialogParameters parameters = new DialogParameters();
            parameters.Add("flag", "0");
            parameters.Add("screen", null);
            dialogService.ShowDialog("screenSetting", parameters, addCallback);
        }

     

        private async void addCallback(IDialogResult result)
        {
            /*
            if (result.Result == ButtonResult.OK)
            {
                ScreenVo screen = result.Parameters.GetValue<ScreenVo>("newScreen");
                if (null != screen)
                {
                    ScreenViewRegionVo screenViewRegion = new ScreenViewRegionVo();
                    screenViewRegion.ScreenId = screen.Id;
                    DialogParameters parameters = new DialogParameters();
                    parameters.Add("screen", screen);
                    MonitorVo monitorVo = new MonitorVo();
                    monitorVo.Screen = screen;
                    string screenView = screenViews[0];
                    string region = regions[0];
                    screenViewRegion.ScreenView = screenView;
                    screenViewRegion.RegionName = region;
                    monitorVo.Monitor = region;
                    screen.RegionName = region;
                    screenViewRegionVos.Add(screenViewRegion);
                    screenIds.Add(screen.Id + "");
                    switch (screenView)
                    {
                        case "Screen":
                            Window screenWin = new Screen();
                            parameters.Add("win", screenWin);
                            screenWin.DataContext = new ScreenViewModel(_eventAggregator, parameters);
                            //sourceWindowList.Add(mp4Player);
                            //手动指定新窗口的viewModel
                            screenWin.ShowInTaskbar = false;
                            screenWin.Top = Convert.ToDouble(screen.OrignY);
                            screenWin.Left = Convert.ToDouble(screen.OrignX);
                            screenWin.Width = Convert.ToDouble(screen.Width);
                            screenWin.Height = Convert.ToDouble(screen.Height);
                            screenWin.Show();
                            screenViews.Remove(screenView);
                            screen.ScreenView = "Screen";

                            break;
                        case "Screen1":
                            screen.ScreenView = "Screen1";
                            Window screenWin1 = new Screen1();
                            parameters.Add("win", screenWin1);
                            screenWin1.DataContext = new ScreenViewModel1(_eventAggregator, parameters);
                            //sourceWindowList.Add(mp4Player);
                            //手动指定新窗口的viewModel
                            screenWin1.ShowInTaskbar = false;
                            screenWin1.Top = Convert.ToDouble(screen.OrignY);
                            screenWin1.Left = Convert.ToDouble(screen.OrignX);
                            screenWin1.Width = Convert.ToDouble(screen.Width);
                            screenWin1.Height = Convert.ToDouble(screen.Height);
                            screenWin1.Show();
                            screenViews.Remove(screenView);

                            break;
                        case "Screen2":
                            screen.ScreenView = "Screen2";
                            Window screenWin2 = new Screen2();
                            parameters.Add("win", screenWin2);
                            screenWin2.DataContext = new ScreenViewModel2(_eventAggregator, parameters);
                            //sourceWindowList.Add(mp4Player);
                            //手动指定新窗口的viewModel
                            screenWin2.ShowInTaskbar = false;
                            screenWin2.Top = Convert.ToDouble(screen.OrignY);
                            screenWin2.Left = Convert.ToDouble(screen.OrignX);
                            screenWin2.Width = Convert.ToDouble(screen.Width);
                            screenWin2.Height = Convert.ToDouble(screen.Height);
                            screenWin2.Show();
                            screenViews.Remove(screenView);

                            break;
                        case "Screen3":
                            screen.ScreenView = "Screen3";
                            Window screenWin3 = new Screen3();
                            parameters.Add("win", screenWin3);
                            screenWin3.DataContext = new ScreenViewModel3(_eventAggregator, parameters);
                            //sourceWindowList.Add(mp4Player);
                            //手动指定新窗口的viewModel
                            screenWin3.ShowInTaskbar = false;
                            screenWin3.Top = Convert.ToDouble(screen.OrignY);
                            screenWin3.Left = Convert.ToDouble(screen.OrignX);
                            screenWin3.Width = Convert.ToDouble(screen.Width);
                            screenWin3.Height = Convert.ToDouble(screen.Height);
                            screenWin3.Show();
                            screenViews.Remove(screenView);

                            break;
                        case "Screen4":
                            screen.ScreenView = "Screen4";
                            Window screenWin4 = new Screen4();
                            parameters.Add("win", screenWin4);
                            screenWin4.DataContext = new ScreenViewModel4(_eventAggregator, parameters);
                            //sourceWindowList.Add(mp4Player);
                            //手动指定新窗口的viewModel
                            screenWin4.ShowInTaskbar = false;
                            screenWin4.Top = Convert.ToDouble(screen.OrignY);
                            screenWin4.Left = Convert.ToDouble(screen.OrignX);
                            screenWin4.Width = Convert.ToDouble(screen.Width);
                            screenWin4.Height = Convert.ToDouble(screen.Height);
                            screenWin4.Show();
                            screenViews.Remove(screenView);

                            break;
                        default:
                            break;


                    }
                    monitorVos.Add(monitorVo);
                    ScreenVos.Add(screen);
                    await showRegion(region);
                }

               
                

            }*/
        }

        private void Received(ObservableCollection<ScreenVo> obj)
        {

            if (null != obj && obj.Count > 0)
            {
                
                if (null != ScreenVos && ScreenVos.Count > 0)
                {
                    ScreenVos.Clear();
                }
                else
                {
                    ScreenVos = new ObservableCollection<ScreenVo>();
                }
                foreach (ScreenVo screen in obj)
                {
                    screen.IsCoincide = isCoincide(screen, obj);

                    if (!screenIds.Contains(screen.Id + ""))
                    {
                        ScreenViewRegionVo screenViewRegion = new ScreenViewRegionVo();
                        screenViewRegion.ScreenId = screen.Id;
                        DialogParameters parameters = new DialogParameters();
                        parameters.Add("screen", screen);


                        MonitorVo monitorVo = new MonitorVo();
                        monitorVo.Screen = screen;
                        string screenView = screenViews[0];
                        string region = regions[0];
                        screenViewRegion.ScreenView = screenView;
                        screenViewRegion.RegionName = region;
                        screenViewRegionVos.Add(screenViewRegion);
                        screenIds.Add(screen.Id + "");
                        switch (screenView)
                        {
                            case "Screen":
                                Window screenWin = new Screen();
                                parameters.Add("win", screenWin);
                                screenWin.DataContext = new ScreenViewModel(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin.ShowInTaskbar = false;
                                screenWin.Top = Convert.ToDouble(screen.OrignY);
                                screenWin.Left = Convert.ToDouble(screen.OrignX);
                                screenWin.Width = Convert.ToDouble(screen.Width);
                                screenWin.Height = Convert.ToDouble(screen.Height);
                                screenWin.Show();
                                screenViews.Remove(screenView);
                                screen.ScreenView = "Screen";
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        screen.RegionName = "Monitor";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor", "Monitor");
                                        }
                                        else {
                                            _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        screen.RegionName = "Monitor1";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor1", "Monitor1");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        screen.RegionName = "Monitor2";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor2", "Monitor2");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        screen.RegionName = "Monitor3";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor3", "Monitor3");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        screen.RegionName = "Monitor4";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor4", "Monitor4");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen1":
                                screen.ScreenView = "Screen1";
                                Window screenWin1 = new Screen1();
                                parameters.Add("win", screenWin1);
                                screenWin1.DataContext = new ScreenViewModel1(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin1.ShowInTaskbar = false;
                                screenWin1.Top = Convert.ToDouble(screen.OrignY);
                                screenWin1.Left = Convert.ToDouble(screen.OrignX);
                                screenWin1.Width = Convert.ToDouble(screen.Width);
                                screenWin1.Height = Convert.ToDouble(screen.Height);
                                screenWin1.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        screen.RegionName = "Monitor";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor", "Monitor");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        screen.RegionName = "Monitor1";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor1", "Monitor1");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        screen.RegionName = "Monitor2";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor2", "Monitor2");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        screen.RegionName = "Monitor3";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor3", "Monitor3");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        screen.RegionName = "Monitor4";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor4", "Monitor4");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen2":
                                screen.ScreenView = "Screen2";
                                Window screenWin2 = new Screen2();
                                parameters.Add("win", screenWin2);
                                screenWin2.DataContext = new ScreenViewModel2(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin2.ShowInTaskbar = false;
                                screenWin2.Top = Convert.ToDouble(screen.OrignY);
                                screenWin2.Left = Convert.ToDouble(screen.OrignX);
                                screenWin2.Width = Convert.ToDouble(screen.Width);
                                screenWin2.Height = Convert.ToDouble(screen.Height);
                                screenWin2.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        screen.RegionName = "Monitor";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor", "Monitor");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        screen.RegionName = "Monitor1";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor1", "Monitor1");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        screen.RegionName = "Monitor2";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor2", "Monitor2");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        screen.RegionName = "Monitor3";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor3", "Monitor3");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        screen.RegionName = "Monitor4";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor4", "Monitor4");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen3":
                                screen.ScreenView = "Screen3";
                                Window screenWin3 = new Screen3();
                                parameters.Add("win", screenWin3);
                                screenWin3.DataContext = new ScreenViewModel3(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin3.ShowInTaskbar = false;
                                screenWin3.Top = Convert.ToDouble(screen.OrignY);
                                screenWin3.Left = Convert.ToDouble(screen.OrignX);
                                screenWin3.Width = Convert.ToDouble(screen.Width);
                                screenWin3.Height = Convert.ToDouble(screen.Height);
                                screenWin3.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        screen.RegionName = "Monitor";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor", "Monitor");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        screen.RegionName = "Monitor1";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor1", "Monitor1");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        screen.RegionName = "Monitor2";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor2", "Monitor2");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        screen.RegionName = "Monitor3";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor3", "Monitor3");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        screen.RegionName = "Monitor4";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor4", "Monitor4");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen4":
                                screen.ScreenView = "Screen4";
                                Window screenWin4 = new Screen4();
                                parameters.Add("win", screenWin4);
                                screenWin4.DataContext = new ScreenViewModel4(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin4.ShowInTaskbar = false;
                                screenWin4.Top = Convert.ToDouble(screen.OrignY);
                                screenWin4.Left = Convert.ToDouble(screen.OrignX);
                                screenWin4.Width = Convert.ToDouble(screen.Width);
                                screenWin4.Height = Convert.ToDouble(screen.Height);
                                screenWin4.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        screen.RegionName = "Monitor";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor", "Monitor");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        screen.RegionName = "Monitor1";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor1", "Monitor1");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        screen.RegionName = "Monitor2";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor2", "Monitor2");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        screen.RegionName = "Monitor3";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor3", "Monitor3");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        screen.RegionName = "Monitor4";
                                        if (userRegions.Contains(region))
                                        {
                                            _regionManager.RequestNavigate("Monitor4", "Monitor4");
                                        }
                                        else
                                        {
                                            _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                            userRegions.Add(region);
                                        }
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            default:
                                break;


                        }
                        monitorVos.Add(monitorVo);
                        //ScreenVos.Add(screen);
                    }
                    else {
                        
                        foreach (ScreenViewRegionVo screenViewRegion in screenViewRegionVos) {
                            if (screenViewRegion.ScreenId == screen.Id) {
                                switch (screenViewRegion.RegionName)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        screen.RegionName = "Monitor";
                                        _regionManager.RequestNavigate("Monitor", "Monitor");
                                        break;
                                    case "Monitor1":
                                        screen.RegionName = "Monitor1";
                                        _regionManager.RequestNavigate("Monitor1", "Monitor1");
                                        
                                        break;
                                    case "Monitor2":
                                        screen.RegionName = "Monitor2";
                                        _regionManager.RequestNavigate("Monitor2", "Monitor2");
                                        
                                        break;
                                    case "Monitor3":
                                        screen.RegionName = "Monitor3";
                                        _regionManager.RequestNavigate("Monitor3", "Monitor3");
                                       
                                        break;
                                    case "Monitor4":
                                        screen.RegionName = "Monitor4";
                                        _regionManager.RequestNavigate("Monitor4", "Monitor4");
                                        
                                        break;
                                }
                            }
                        }
                    }
                    ScreenVos.Add(screen);
                    _eventAggregator.GetEvent<ScreenClearEvent>().Publish(screen);
                }
                _eventAggregator.GetEvent<RefreshSorceListEvent>().Publish(program);
                _eventAggregator.GetEvent<OpenScreenEvent>().Publish(screenIds);
                _eventAggregator.GetEvent<GetMonitorEvent>().Publish(monitorVos);
                _eventAggregator.GetEvent<UpdateCoincideEvent>().Publish(ScreenVos);
            }

        }

        public ObservableCollection<ScreenVo> ScreenVos { get { return screenVos; } set { screenVos = value; RaisePropertyChanged(); } }

        public ScreenVo SelectedItem { get { return selectedItem; } set { this.selectedItem = value; RaisePropertyChanged(); } }

        public ListBox ListBox { get => listBox; set => listBox = value; }

        List<MonitorVo> monitorVos = new List<MonitorVo>();
        private bool isCoincide(ScreenVo screen, ObservableCollection<ScreenVo> screenVos)
        {
            bool flag = false;
            //screenVos.Remove(screen);
            Rect rect = new Rect(screen.OrignX,screen.OrignY, screen.Width, screen.Height);
            if (null != screenVos && screenVos.Count > 0)
            {
                for (int i=0;i<screenVos.Count;i++)
                {
                    ScreenVo screen1 = screenVos[i];
                    if (screen.Id == screen1.Id) {
                        continue;
                    }
                    Rect rect1 = new Rect(screen1.OrignX, screen1.OrignY, screen1.Width, screen1.Height);
                    if(!(rect.Right <= rect1.Left || rect.Left >= rect1.Right || rect.Bottom <= rect1.Top || rect.Top >= rect1.Bottom)) {
                        return true; 
                    }
                }
            }
            return flag;
        }
        private void initScreenList()
        {
            ScreenVos.Clear();
            string filePath = AppDomain.CurrentDomain.BaseDirectory + "/Config/screenlist.info";
            if (File.Exists(filePath))
            {
                string content = WriteFileUtil.readFile(filePath);
                if (!String.IsNullOrEmpty(content))
                {
                    ScreenVos = JsonConvert.DeserializeObject<ObservableCollection<ScreenVo>>(content);
                }

                //打开屏幕
                if (null != ScreenVos && ScreenVos.Count > 0)
                {

                    for (int i = 0; i < ScreenVos.Count; i++)
                    {
                        ScreenViewRegionVo screenViewRegion = new ScreenViewRegionVo();
                        screenViewRegion.ScreenId = ScreenVos[i].Id;
                        DialogParameters parameters = new DialogParameters();
                        ScreenVos[i].IsCoincide = isCoincide(ScreenVos[i], ScreenVos);
                        parameters.Add("screen", ScreenVos[i]);


                        MonitorVo monitorVo = new MonitorVo();
                        monitorVo.Screen = ScreenVos[i];
                        string screenView = screenViews[0];
                        string region = regions[0];
                        screenViewRegion.ScreenView = screenView;
                        screenViewRegion.RegionName = region;
                        screenViewRegionVos.Add(screenViewRegion);
                        screenIds.Add(ScreenVos[i].Id + "");
                        userRegions.Add(region);
                        switch (screenView)
                        {
                            case "Screen":
                                Window screenWin = new Screen();
                                parameters.Add("win", screenWin);
                                screenWin.DataContext = new ScreenViewModel(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin.ShowInTaskbar = false;
                                screenWin.Top = Convert.ToDouble(ScreenVos[i].OrignY);
                                screenWin.Left = Convert.ToDouble(ScreenVos[i].OrignX);
                                screenWin.Width = Convert.ToDouble(ScreenVos[i].Width);
                                screenWin.Height = Convert.ToDouble(ScreenVos[i].Height);
                                screenWin.Show();
                                screenViews.Remove(screenView);
                                ScreenVos[i].ScreenView = "Screen";
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        ScreenVos[i].RegionName = "Monitor";
                                        _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        ScreenVos[i].RegionName = "Monitor1";
                                        _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        ScreenVos[i].RegionName = "Monitor2";
                                        _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        ScreenVos[i].RegionName = "Monitor3";
                                        _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        ScreenVos[i].RegionName = "Monitor4";
                                        _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen1":
                                ScreenVos[i].ScreenView = "Screen1";
                                Window screenWin1 = new Screen1();
                                parameters.Add("win", screenWin1);
                                screenWin1.DataContext = new ScreenViewModel1(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin1.ShowInTaskbar = false;
                                screenWin1.Top = Convert.ToDouble(ScreenVos[i].OrignY);
                                screenWin1.Left = Convert.ToDouble(ScreenVos[i].OrignX);
                                screenWin1.Width = Convert.ToDouble(ScreenVos[i].Width);
                                screenWin1.Height = Convert.ToDouble(ScreenVos[i].Height);
                                screenWin1.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        ScreenVos[i].RegionName = "Monitor";
                                        _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        ScreenVos[i].RegionName = "Monitor1";
                                        _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        ScreenVos[i].RegionName = "Monitor2";
                                        _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        ScreenVos[i].RegionName = "Monitor3";
                                        _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        ScreenVos[i].RegionName = "Monitor4";
                                        _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen2":
                                ScreenVos[i].ScreenView = "Screen2";
                                Window screenWin2 = new Screen2();
                                parameters.Add("win", screenWin2);
                                screenWin2.DataContext = new ScreenViewModel2(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin2.ShowInTaskbar = false;
                                screenWin2.Top = Convert.ToDouble(ScreenVos[i].OrignY);
                                screenWin2.Left = Convert.ToDouble(ScreenVos[i].OrignX);
                                screenWin2.Width = Convert.ToDouble(ScreenVos[i].Width);
                                screenWin2.Height = Convert.ToDouble(ScreenVos[i].Height);
                                screenWin2.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        ScreenVos[i].RegionName = "Monitor";
                                        _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        ScreenVos[i].RegionName = "Monitor1";
                                        _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        ScreenVos[i].RegionName = "Monitor2";
                                        _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        ScreenVos[i].RegionName = "Monitor3";
                                        _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        ScreenVos[i].RegionName = "Monitor4";
                                        _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen3":
                                ScreenVos[i].ScreenView = "Screen3";
                                Window screenWin3 = new Screen3();
                                parameters.Add("win", screenWin3);
                                screenWin3.DataContext = new ScreenViewModel3(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin3.ShowInTaskbar = false;
                                screenWin3.Top = Convert.ToDouble(ScreenVos[i].OrignY);
                                screenWin3.Left = Convert.ToDouble(ScreenVos[i].OrignX);
                                screenWin3.Width = Convert.ToDouble(ScreenVos[i].Width);
                                screenWin3.Height = Convert.ToDouble(ScreenVos[i].Height);
                                screenWin3.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        ScreenVos[i].RegionName = "Monitor";
                                        _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        ScreenVos[i].RegionName = "Monitor1";
                                        _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        ScreenVos[i].RegionName = "Monitor2";
                                        _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        ScreenVos[i].RegionName = "Monitor3";
                                        _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        ScreenVos[i].RegionName = "Monitor4";
                                        _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            case "Screen4":
                                ScreenVos[i].ScreenView = "Screen4";
                                Window screenWin4 = new Screen4();
                                parameters.Add("win", screenWin4);
                                screenWin4.DataContext = new ScreenViewModel4(_eventAggregator, parameters);
                                //sourceWindowList.Add(mp4Player);
                                //手动指定新窗口的viewModel
                                screenWin4.ShowInTaskbar = false;
                                screenWin4.Top = Convert.ToDouble(ScreenVos[i].OrignY);
                                screenWin4.Left = Convert.ToDouble(ScreenVos[i].OrignX);
                                screenWin4.Width = Convert.ToDouble(ScreenVos[i].Width);
                                screenWin4.Height = Convert.ToDouble(ScreenVos[i].Height);
                                screenWin4.Show();
                                screenViews.Remove(screenView);
                                switch (region)
                                {
                                    case "Monitor":
                                        //屏幕监控
                                        ScreenVos[i].RegionName = "Monitor";
                                        _regionManager.RegisterViewWithRegion("Monitor", "Monitor");
                                        monitorVo.Monitor = "Monitor";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor1":
                                        ScreenVos[i].RegionName = "Monitor1";
                                        _regionManager.RegisterViewWithRegion("Monitor1", "Monitor1");
                                        monitorVo.Monitor = "Monitor1";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor2":
                                        ScreenVos[i].RegionName = "Monitor2";
                                        _regionManager.RegisterViewWithRegion("Monitor2", "Monitor2");
                                        monitorVo.Monitor = "Monitor2";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor3":
                                        ScreenVos[i].RegionName = "Monitor3";
                                        _regionManager.RegisterViewWithRegion("Monitor3", "Monitor3");
                                        monitorVo.Monitor = "Monitor3";
                                        regions.Remove(region);
                                        break;
                                    case "Monitor4":
                                        ScreenVos[i].RegionName = "Monitor4";
                                        _regionManager.RegisterViewWithRegion("Monitor4", "Monitor4");
                                        monitorVo.Monitor = "Monitor4";
                                        regions.Remove(region);
                                        break;
                                }
                                break;
                            default:
                                break;


                        }
                        monitorVos.Add(monitorVo);
                    }
                   // _eventAggregator.GetEvent<GetMonitorEvent>().Publish(monitorVos);
                    //_eventAggregator.GetEvent<OpenScreenEvent>().Publish(screenIds);
                }
            }
        }
    }
}
